package com.example.friend.controller;

import com.example.common.core.constants.HttpConstants;
import com.example.common.core.controller.BaseController;
import com.example.common.core.model.R;
import com.example.common.core.model.vo.LoginUserVO;
import com.example.common.file.model.OSSResult;
import com.example.common.message.service.AliSmsService;
import com.example.friend.model.user.dto.UserDTO;
import com.example.friend.model.user.dto.UserUpdateDTO;
import com.example.friend.model.user.vo.UserVO;
import com.example.friend.service.IFileService;
import com.example.friend.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * 功能描述:
 *
 * @author Lenovo
 * @date 2025/3/26
 */
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {
    @Resource
    private IUserService userService;

    @Resource
    private IFileService fileService;
    @PostMapping("/sendCode")
    public R<Void> sendCode(@RequestBody UserDTO userDTO){
        boolean result = userService.sendCode(userDTO);
        return toResult(result);
    }

    @PostMapping("/code/login")
    public R<String> codeLogin(@RequestBody UserDTO userDTO){
        String token = userService.codeLogin(userDTO.getPhone(),userDTO.getCode());
        return R.ok(token);
    }

    @DeleteMapping("/logout")
    public R<Void> logout(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return toResult(userService.logout(token));
    }

    @GetMapping("/info")
    public R<LoginUserVO> info(@RequestHeader(HttpConstants.AUTHENTICATION) String token){
        return userService.info(token);
    }

    @GetMapping("/detail")
    public R<UserVO> detail() {
        return R.ok(userService.detail());
    }

    @PutMapping("/edit")
    public R<Void> edit(@RequestBody UserUpdateDTO userUpdateDTO) {
        return toResult(userService.edit(userUpdateDTO));
    }

    @PutMapping("/head-image/update")
    public R<Void> updateHeadImage(@RequestBody UserUpdateDTO  userUpdateDTO) {
        return toResult(userService.updateHeadImage(userUpdateDTO.getHeadImage()));
    }
}
